#include "stdafx.h"

#include <QAbstractNativeEventFilter>

#include "GlobalHotkey.h"
#include <QMessageBox>
#include "TCpu.h"
#include "TSearcherWindow.h"

bool GlobaoHotkeyEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
{
    if (eventType == "windows_dispatcher_MSG" || eventType == "windows_generic_MSG") {
        MSG* msg = static_cast<MSG *>(message);
        if (msg->message == WM_HOTKEY)
        {
            if (msg->lParam == MAKELONG(MOD_CONTROL, VK_END))
            {
                TCpu::instance()->togglePause();
            }
            else if (msg->lParam == MAKELONG(MOD_CONTROL, VK_INSERT))
            {
                auto ts = TSearcherWindow::instance();
                if (ts->isVisible())
                    ts->hide();
                else
                    ts->show();
            }
        }
    }
    return false;
}

void GlobaoHotkeyEventFilter::registerThis()
{
    QCoreApplication::instance()->installNativeEventFilter(new GlobaoHotkeyEventFilter);
    RegisterHotKey(NULL, 0, MOD_CONTROL | MOD_NOREPEAT, VK_END);
    RegisterHotKey(NULL, 0, MOD_CONTROL | MOD_NOREPEAT, VK_INSERT); 
}
